/*
     Copyright 2007 Joseph M. Ferner

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using System.Reflection;
using NUnit.Framework;
#pragma warning disable 169

namespace OpenServers.Net.Common.Utils {
    [TestFixture]
    public class PrivateStaticObjectTest {
        private PrivateStaticObject _privateStaticObject;

        [SetUp]
        public void SetUp() {
            _privateStaticObject = new PrivateStaticObject(typeof(MyObject));
        }

        [Test]
        public void GetMethod() {
            MethodInfo mi = _privateStaticObject.GetMethod("Method1", new Type[] { typeof(string), typeof(string) });
            Assert.IsNotNull(mi);
        }

        [Test]
        public void GetMethodBadMethod() {
            MethodInfo mi = _privateStaticObject.GetMethod("MethodBadMethod", new Type[] { typeof(string), typeof(string) });
            Assert.IsNull(mi);
        }


        [Test]
        public void SetStaticField() {
            _privateStaticObject.SetStaticFieldValue("a", "newval");
        }

        [Test]
        public void SetStaticFieldBadField() {
            try {
                _privateStaticObject.SetStaticFieldValue("badField", "newval");
                Assert.Fail("should have failed");
            } catch (FieldAccessException) {
            }
        }

        [Test]
        public void GetMethods() {
            MethodInfo[] methods = _privateStaticObject.GetMethods("Method1");
            Assert.AreEqual(2, methods.Length);
        }

        [Test]
        public void GetMethodsParameterCount() {
            MethodInfo[] methods = _privateStaticObject.GetMethods("Method1", 1);
            Assert.AreEqual(1, methods.Length);
        }

#pragma warning disable 168
        public class MyObject {
            private static string a;

            protected void Method1(string b, string c) {

            }

            protected void Method1(string b) {

            }
        }
#pragma warning restore 168
    }
}
